var app = getApp();
Page({
  data: {
    inputFocus: false,
    searchHis: [],
    inputValue1:"",
    inputValue2:"",
    inputValue3:"",
    inputValue4:"",
    inputValue5:"",
    historyShow: false,
    clearShow: false, // 点叉了吗
    winHeight: "",//窗口高度
    currentTab: 0, //预设当前项的值
    scrollLeft: 0, //tab标题的滚动条位置
    juge:false,
    item: {
      code:'',
    }, // 基本信息
    code: '', // 设备编号
    information:[], // 基本信息
    fixArr:[], // 维修工单
    protectArr:[], // 保养工单
    selectArr:[], // 巡检工单
    qControl:[], // 质控工单
    scnenArr:[], // 现场更正记录

    expertList: [],
    userData:{}
  },
  // 获取维修工单
  _getFix() {
    let obj = {};
    console.log(this.data.code)
    // obj.serialOrLotNumber = "110555";
    obj.serialOrLotNumber = this.data.item.serialOrLotNumber;
    obj.purposeOfVisit = "Corrective Maintenance (CM)";
    obj.workOrderNumber = this.data.inputValue1
    this.axios.jrsfRequest("/api/AllInstalledProducts/getOrderList", obj, "POST").then((res) => {
      this.setData({
        fixArr:res.data
      })
      console.log(res, '维修工单')
    })
  },
    // 事件触发函数
    clear() {
      this.setData({
        inputValue1: '',
        inputValue2: '',
        inputValue3: '',
        inputValue4: '',
        inputValue5: '',
        clearShow: false,
      })
      this._getFix()
      this._getProtect()
      this._getSelect()
      this._getScnen()
      console.log('小图标不配绑定事件？')
    },
  watchInput(event) {
    let juge = this.data.clearShow
    if (!juge) {
      this.setData({
        clearShow: true,
      })
    }
    this.data.inputValue1 = event.detail.value
    console.log('输入的话', event.detail)
  },
  watchInput2(event) {
    let juge = this.data.clearShow
    if (!juge) {
      this.setData({
        clearShow: true,
      })
    }
    this.data.inputValue2 = event.detail.value
    console.log('输入的话', event.detail)
  },
    watchInput3(event) {
    let juge = this.data.clearShow
    if (!juge) {
      this.setData({
        clearShow: true,
      })
    }
    this.data.inputValue3 = event.detail.value
    console.log('输入的话', event.detail)
  },
  watchInput4(event) {
    let juge = this.data.clearShow
    if (!juge) {
      this.setData({
        clearShow: true,
      })
    }
    this.data.inputValue4 = event.detail.value
    console.log('输入的话', event.detail)
  },
  userdetail(e){
    // wx.showActionSheet({
    //   itemList: ['A', 'B', 'C'],
    //   success: function (res) {
    //     wx.hideToast()
    //     console.log(res);
    //   }
    // })
    // wx.showToast({
    //   title: '纯文字弹窗',
    //   icon: 'none',    //如果要纯文本，不要icon，将值设为'none'
    //   duration: 2000     
    // }) 
    this.axios.custom("Staff","selectStaffInformation",{id:e.currentTarget.dataset.id} )
    .then((result) => {
      console.log(result)
      this.setData({
        userData:result.data
      })
    });
    e.currentTarget.dataset
    console.log(e.currentTarget.dataset)
    this.setData({
      juge:true
    })
  },
  cancle(){
    this.setData({
      juge:false
    })
  },
   // 保养工单
   _getProtect() {
    let obj = {};
    // obj.serialOrLotNumber = "110555";
    obj.serialOrLotNumber = this.data.item.serialOrLotNumber;
    obj.purposeOfVisit = "Preventative Maintenance (PM)";
    obj.workOrderNumber = this.data.inputValue2
    this.axios.jrsfRequest("/api/AllInstalledProducts/getOrderList", obj, "POST").then((res) => {
      this.setData({
        protectArr:res.data
      })
      console.log(res, '保养工单')
    })
  },
  //质控详情
  toDetail(e){
    const { item } = e.currentTarget.dataset
    console.log(e)
    let that = this;
    // 当传递的数据过多的时候 使用eventChannel的方式来传值
    wx.navigateTo({
      url: '/pages/equipment/qualityControl/index',
      success: function (res) {
       
        res.eventChannel.emit('toEqDetail', {item:e.currentTarget.dataset.item,serialOrLotNumber:that.data.item.serialOrLotNumber})
      }
    })
  },
  // 维修报告详情
  torepairDetail(e){
    const { item } = e.currentTarget.dataset
    console.log(e)
    let that = this;
    // 当传递的数据过多的时候 使用eventChannel的方式来传值
    wx.navigateTo({
      url: '/pages/equipment/eqDetail/repair/index',
      success: function (res) {
        res.eventChannel.emit('toEqDetail', {item:e.currentTarget.dataset.item,serialOrLotNumber:that.data.item.serialOrLotNumber})
      }
    })
  },
  // 获取巡检工单
  _getSelect() {
    let obj = {};
    obj.serialOrLotNumber = this.data.item.serialOrLotNumber;
    //obj.serialOrLotNumber = "110553";
    obj.purposeOfVisit = "Customer Visit";
    obj.workOrderNumber = this.data.inputValue3
    this.axios.jrsfRequest("/api/AllInstalledProducts/getOrderList", obj, "POST").then((res) => {
      this.setData({
        selectArr:res.data
      })
      console.log(res, '巡检工单')
    })
  },
  // 获取质控
  _getQcontrol(){
    let obj = {};
    //obj.id = "110133";
    obj.id = this.data.item.serialOrLotNumber;
    this.axios.jrsfRequest("/api/AllInstalledProducts/getQc", obj, "POST").then((res) => {

      console.log(res, '质控工单')
      res.data.forEach(e=>{
        e.insertTime = e.insertTime.substring(0,e.insertTime.length-8).trim()
      })
      this.setData({
        qControl:res.data
      })
    })
  },
  // 获取现场更正
  _getScnen(){
    let obj = {};
    //obj.serialOrLotNumber = this.data.code;
    obj.serialOrLotNumber = this.data.item.serialOrLotNumber;
    obj.workOrderNumber = this.data.inputValue4
    // obj.serialOrLotNumber = "110555";
    obj.purposeOfVisit = "Field Action,Entitlement Fulfillment (EF)";
    this.axios.jrsfRequest("/api/AllInstalledProducts/getOrderList", obj, "POST").then((res) => {
      this.setData({
        scnenArr:res.data
      })
      console.log(res, '现场更正')
    })
  },
  // 滚动切换标签样式
  switchTab: function (e) {
    this.setData({
      currentTab: e.detail.current
    });
    console.log('进场执行？')
    this.checkCor();
  },
  // 点击标题切换当前页时改变样式
  swichNav: function (e) {
    var cur = e.target.dataset.current;
    if (this.data.currentTaB == cur) { return false; }
    else {
      this.setData({
        currentTab: cur
      })
    }
  },
  //判断当前滚动超过一屏时，设置tab标题滚动条。
  checkCor: function () {
    if (this.data.currentTab > 4) {
      this.setData({
        scrollLeft: 300
      })
    } else {
      this.setData({
        scrollLeft: 0
      })
    }
  },
  onLoad: function (option) {

    var that = this;
    // 高度自适应
    wx.getSystemInfo({
      success: function (res) {
        var clientHeight = res.windowHeight,
          clientWidth = res.windowWidth,
          rpxR = 750 / clientWidth;
        var calc = clientHeight * rpxR - 180;
        console.log(calc)
        that.setData({
          winHeight: calc
        });
      }
    });
    const eventChannel = this.getOpenerEventChannel();
    // 监听 index页面定义的toHome 事件
    eventChannel.on('toEqDetail', (res) => {
      res.dateInstalledtwo = res.dateInstalled.substring(0,res.dateInstalled.length-8)
      this.setData({
        item: res
      })
      this._getFix();
      this._getQcontrol();
      this._getProtect();
      this._getSelect();
      this._getScnen();
      console.log(res, '页面传值')
    })


  },
onShow:function(){
  const eventChannel = this.getOpenerEventChannel();
  // 监听 index页面定义的toHome 事件
  eventChannel.on('toEqDetail', (res) => {
    this.setData({
      item: res
    })
    console.log(res, '页面传值')
  })

  this._getFix();
  this._getQcontrol();
  this._getProtect();
  this._getSelect();
  this._getScnen();
}
})
